<!--
 * @Description: 构建过渡页面上的显示
 * @ComposerRequire: 
 * @ComposerRemove: 
 * @Author: 阿海 <764882431@qq.com>
 * @Date: 2021-06-02 14:47:46
 * @LastEditTime: 2021-06-23 09:49:56
 * @LastEditors: 阿海
-->
<script>
    var dispatchInterval  = null;
    
    function builderDispatch(resData){
        $(".layadmin-form").addClass("layui-hide");
        $(".layadmin-table").addClass("layui-hide");
        $(".dispatch-page").removeClass("layui-hide");
        $(".page_title").addClass("layui-hide");
        resData.form_result?$(".dispatch-title i").addClass(resData.icon_success):$(".dispatch-title i").addClass(resData.icon_error);
        resData.form_result?$(".dispatch-title i").css("color","#1E9FFF"):$(".dispatch-title i").css("color","#FF5722");
        resData.form_result?$(".dispatch-info").children("a").attr("_result",1):$(".dispatch-info").children("a").attr("_result",0);


        $(".dispatch-description").html(resData.title);
        resData.is_hash?$(".dispatch-info").children("a").attr("_href",resData.location_hash):$(".dispatch-info").children("a").attr("_href",resData.location_url);
        resData.is_hash?$(".dispatch-info").children("a").attr("is_hash",1):$(".dispatch-info").children("a").attr("is_hash",0);
        resData.base_url ? $(".dispatch-info").children("a").attr("base_url", resData.base_url) : $(".dispatch-info").children("a").attr("base_url", '');

        $("#wait").html(resData.wait_time);
        dispatchInterval = setInterval(() => {
            resData.wait_time --;
            // console.log(resData.wait_time);
            if(resData.wait_time<=0){
                clearInterval(dispatchInterval);    
                
                if(resData.is_hash){
                    if(location.hash.slice(1) == resData.location_hash){
                        location.reload();
                        return ;
                    }
                    // console.log(resData.base_url+"#"+ resData.location_hash);
                    // location.hash = resData.location_hash;
                    if(resData.form_result){
                        window.location.href = resData.base_url +"#"+ resData.location_hash;
                    }else{
                        //如果错误则返回上一级
                        history.back(-1);
                    }
                    return ;
                }
                if(!resData.is_hash){
                    window.location.href = resData.location_url;
                    return ;
                }
            }
            $("#wait").html(resData.wait_time);
        }, 1000);
        
    }
    function dispatchUrl(obj){
        layui.use(["layer"],function(){
            var url = $(obj).attr("_href");
            var result = $(obj).attr("_result");
            var is_hash = $(obj).attr("is_hash");
            var base_url = $(obj).attr("base_url");
            url == ''?layer.msg("未设置跳转的路由",function(){}):'';
            if(result == 0){
                history.back(-1);
                return '';
            }
            clearInterval(dispatchInterval);
            if(is_hash == 1){
                if(location.hash.slice(1) == url){
                    location.reload();
                    return ;
                }
                window.location.href = base_url+"#"+url;
            }else{
                window.location.href = url;
            }
            return ;
        });
    }  
</script>